<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html>

<%
	List<String>list = new ArrayList<String>();
	list.add("apple");
	list.add("pear");
	list.add("orange");
	list.add("red");
	list.add("green");
	list.add("white");
	request.setAttribute("arg", list);
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>foreach</title>
</head>
<body>
	<!-- 全部遍历 -->
	<c:forEach var="block" items="${requestScope.arg}">
		<h2><c:out value="${block}"></c:out></h2>
	</c:forEach>
	
	<hr>
	
	<!-- 部分遍历 -->
	<c:forEach var="block" items="${requestScope.arg}" begin="1" end="4">
		<h2><c:out value="${block}"></c:out></h2>
	</c:forEach>
	
	<hr>
	
	<!-- 指定步长 -->
	<c:forEach var="block" items="${requestScope.arg}" step="2">
		<h2><c:out value="${block}"></c:out></h2>
	</c:forEach>
	
	<hr>
	
	<!--输出状态  -->
	<c:forEach var="block" items="${requestScope.arg}" varStatus="var">
		<h2><c:out value="元素：${block}"></c:out></h2>
		<h2><c:out value="index：${var.index}"></c:out></h2>
		<h2><c:out value="count：${var.count}"></c:out></h2>
		<h2><c:out value="first：${var.first}"></c:out></h2>
		<h2><c:out value="last：${var.last}"></c:out></h2>
	</c:forEach>

	<c:forTokens items="1-2-3-4-5-6-7-8-9-10" delims="-" var="num">
		<c:out value="${num}"></c:out><br>
	</c:forTokens>

</body>
</html>







